package com.shopping_assistant.model;

import java.util.Comparator;

public class VisitCounter {
	
	private Person person;
	private Shop shop;
	private int totalVisits;
	
	public VisitCounter(Person person, Shop shop) {
		this.person = person;
		this.shop = shop;
		totalVisits = 0;
	}
	
	public VisitCounter(Person person, Shop shop, int totalVisits) {
		this.person = person;
		this.shop = shop;
		this.totalVisits = totalVisits;
	}
	
	public void countVisit() {
		totalVisits++;
	}

	public int getTotalVisits() {
		return totalVisits;
	}
	
	public Person getPerson() {
		return person;
	}
	
	public Shop getShop() {
		return shop;
	}
	
	public static Comparator<VisitCounter> compareByCount() {
		return new sortShops();
	}
	
	private static class sortShops implements Comparator<VisitCounter> {

		public int compare(VisitCounter lhs, VisitCounter rhs) {
			return rhs.totalVisits - lhs.totalVisits;
		}
	}
	
	@Override
	public String toString() {
		return shop.getName() + " [" + totalVisits + "]";
	}
}
